package com.list88zhu.android.sunflower;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.list88zhu.android.sunflower.jetpack.PlantAddActivity;
import com.list88zhu.android.sunflower.jetpack.PlantQueryActivity;
import com.list88zhu.android.sunflower.jetpack.room.AppDatabase;
import com.list88zhu.android.sunflower.jetpack.room.Plant;

import java.util.List;

/**
 * <pre><code>
 *
 *  </code></pre>
 *
 * @author zhuyingming@qmtv.com
 * @date 2018/8/26
 */
public class RoomActivity extends AppCompatActivity {

    private static final String TAG = "RoomActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_room);

        findViewById(R.id.addPlant).setOnClickListener(view -> startActivity(new Intent(RoomActivity.this, PlantAddActivity.class)));
        findViewById(R.id.queryPlant).setOnClickListener(view -> {
            List<Plant> plantList = AppDatabase.getDefault(this).getPlantDao().getAllPlants();
            for(Plant plant : plantList) {
                Log.d(TAG, "id = " + plant.getId() +", title = " + plant.getTitle()
                    +", content = " + plant.getContent()+", beginDate = "+plant.getBeginDate()
                    +", endDate = " + plant.getEndDate());
            }
            startActivity(new Intent(RoomActivity.this, PlantQueryActivity.class));
        });
    }
}
